package com.sx.pipeline.ui.supply.approve.frag

import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.noober.background.view.BLTextView
import com.sx.pipeline.R
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.repos.http.res.ReleaseSupplyVo

/**
 * @Author：YY
 * @Date：2022/2/10
 * @Describe: 审批供应列表适配器
 */
class ApprovalSupplyListAdapter(
) : BaseQuickAdapter<ReleaseSupplyVo, BaseViewHolder>(
    R.layout.item_release_needs_list
) {
    /**
     * 同意需求
     */
    var agreeRequireCallback: ((Int) -> Unit)? = null

    /**
     * 拒绝需求
     */
    var rejectRequireCallback: ((Int) -> Unit)? = null
    override fun convert(holder: BaseViewHolder, item: ReleaseSupplyVo) {
        //任务时间
        holder.setText(R.id.tv_time,item.createTime)
        //任务标题
        holder.setText(R.id.tv_title,item.title)
        //供应时间
        holder.setText(R.id.tv_need_time,"供应时间：${item.startTime}-${item.endTime}")
        //供应服务区域
        holder.setText(R.id.tv_need_address,"供应服务区域：${item.addressDetail}")
        //供应负责人
        holder.setText(R.id.tv_contact,"供应负责人：${item.contact}")
        //供应联系方式
        holder.setText(R.id.tv_contact_num,"联系方式：${item.contactPhone}")
        //管币价格
        holder.setText(R.id.tv_money,""+item.payMoney)
        when (item.status) {
            //待审核
            0 -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_pending_review))
                holder.setText(R.id.tv_action, context.getString(R.string.txt_agree_supply))
                holder.setText(R.id.tv_delete, context.getString(R.string.txt_denial_supply))
                holder.setVisible(R.id.tv_action, true)
                holder.setVisible(R.id.tv_delete, true)
            }
            //已通过
            1 -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_passed))

                holder.setVisible(R.id.tv_action, false)
                holder.setVisible(R.id.tv_delete, false)
            }
            //已驳回
            5 -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_rejected))

                holder.setText(R.id.tv_action, context.getString(R.string.txt_rejection_reason))
                holder.setVisible(R.id.tv_action, true)
                holder.setVisible(R.id.tv_delete, false)
            }
        }

        holder.getView<BLTextView>(R.id.tv_action).setOnClickListener {
            when (item.status) {
                //同意需求
                0 -> agreeRequireCallback?.invoke(item.id)
                //查看原因
                2 -> ARouter.getInstance().build(RoutePath.Mine.CONSTRUCTION_NEEDS_DETAIL).navigation()
            }
        }
        holder.getView<BLTextView>(R.id.tv_delete).setOnClickListener {
            when (item.status) {
                //拒绝需求
                0 -> rejectRequireCallback?.invoke(item.id)
            }
        }
    }
}